package com.tianqu.tms.www.member.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.CarImage;
import com.tianqu.tms.www.member.actionform.MemberInputActionForm;
import com.tianqu.tms.www.member.viewhelper.MemberInputViewHelper;
/**
 * 
 * 会员基本信息修改确认页面Action
 * 
 * @author tianshifu
 *
 */
public class MemberUDBaseConfirmAction extends TmsAction {
	
	private static final String IMGLIST = "imgList";//图片list

	private Logger logger = Logger.getLogger(MemberUDBaseConfirmAction.class);
	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		//从uc中获取会员信息，通过form重构viewhelp
		MemberInputViewHelper view = (MemberInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		
		//从mapList中取出图片信息set到viewhelp中 替换掉旧图片
		List<CarImage> imgList = new ArrayList<CarImage>();
		if(uc.getAttribute(IMGLIST)!=null)
		{
			imgList = (List<CarImage>)uc.getAttribute(IMGLIST);
		}
		if(imgList!=null)
		{
			//将list中的数据取出set到viewhelp中
			for(int i=0;i<imgList.size();i++)
			{
				CarImage entity = (CarImage)imgList.get(i);
				if(entity.getImgKey().equals(TmsConstants.ONE))
				{
					view.setOrgPhoto(entity.getImgPath());
				}
				if(entity.getImgKey().equals(TmsConstants.TWO))
				{
					view.setBusinessPhoto(entity.getImgPath());
				}
				if(entity.getImgKey().equals(TmsConstants.THREE))
				{
					view.setCardPhoto(entity.getImgPath());
				}
				if(entity.getImgKey().equals(TmsConstants.FIVE))
				{
					view.setMemberZipCode(entity.getImgPath());
				}
			}
			
		}
		
		request.setAttribute(TmsConstants.VIEWHELP, view);//
		uc.removeAttribute(TmsConstants.VIEWHELP);
		uc.setAttribute(TmsConstants.VIEWHELP, view);//将view set到uc中待结果页面进行更新操作
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

	
}
